<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\service\MarketSMCopywriting as MarketSMCopywritingService;
use app\admin\validate\MarketSMCopywriting as MarketSMCopywritingValidate;
use think\Request;

class MarketSMCopywriting
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }

    /**
     * 发布社媒文案到社媒平台
     * @param Request $request
     * @param MarketSMCopywritingService $service
     * @param MarketSMCopywritingValidate $validate
     * @return \think\response\Json
     */
    public function publish(Request $request, MarketSMCopywritingService $service, MarketSMCopywritingValidate $validate){
        $checkData = $request->param();
        if (!$validate->scene('publish')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['ids'] =  $request->param('ids', []);

        $arrData = $service->publish($param);
        return json($arrData);
    }

    /**
     * 重新生成
     * @param Request $request
     * @param MarketSMCopywritingService $service
     * @param MarketSMCopywritingValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function regenerate(Request $request, MarketSMCopywritingService $service, MarketSMCopywritingValidate $validate){
        $checkData = $request->param();
        if (!$validate->scene('regenerate')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['id'] =  $request->param('id', null);

        $arrData = $service->regenerate($param);
        return json($arrData);
    }

    /**
     * 编辑文案内容
     * @param Request $request
     * @param MarketSMCopywritingService $service
     * @param MarketSMCopywritingValidate $validate
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function editContent(Request $request, MarketSMCopywritingService $service, MarketSMCopywritingValidate $validate){
        $checkData = $request->param();
        if (!$validate->scene('editContent')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;
        $param['id'] =  $request->param('id', null);
        $param['content'] =  $request->param('content', '');

        $arrData = $service->editContent($param);
        return json($arrData);
    }
}
